/**
* mpsvr子进程
* @author thinkry
*/

#ifndef __MPSVR_HANDLE_H__
#define __MPSVR_HANDLE_H__

#include "mpdef.h"
#include <net/CTSocket.h>
#include "CTBuffer.h"
#include "CTSoBase.h"

/**
* mpsvr子进程类
*/
class CMpHandle
{
protected:
    static bool s_bReloadConfig;
    static bool s_bExit;

    CTSocket    m_stSocket;
    CTBuffer    m_stRecvBuffer;
    CTBuffer    m_stSendBuffer;

public:
    CMpHandle();
    virtual ~CMpHandle();

    /** 初始化 */
    void Init();

    /** 主循环 */
    void Run();

    /** 退出 */
    void Exit();

    static void sigusr1_handle(int iSigVal);
    static void sigusr2_handle(int iSigVal);

protected:
	CTSoAppInf* m_pstSoApp;
	CTSoLoader	m_stSoLoader;

protected:
    void ReloadConfig();
    int RecvOneCode(char*& pszCodeBuf, int& iCodeLen);
    void Send();

    int Test(const char* pszReqBuf, int iReqLen,
              char* pszAnsBuf, int iAnsBufLen, int& iAnsLen);

};

#endif //__MPSVR_HANDLE_H__
